var setupTask;
var reviveCount = 5;
var mapIds = [867147100, 867147200, 867147300, 867147400, 867147500, 867147600, 867147700, 867147800, 867147900, 867148000, 867148100, 867148200, 867148300, 867148400, 867148500];
var 准备地图 = 867147001;
var eventName = "深渊远征队";

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    c.schedule("声望", 20 * 1000);
    c.schedule("暗影", 60 * 1000);
    c.schedule("补给", 60 * 1000);
    return c
}

function 声望(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().addNumberForQuestInfo(64753, "point", 1)
    });
    a.schedule("声望", 20 * 1000)
}

function 暗影(b) {
    var a = new Date().getMinutes();
    if (a % 30 == 29) {
        b.getPlayers().forEach(function (c) {
            c.getAPI().fieldEffect_ScreenMsg("Effect/EffectPL.img/AbyssShadow");
            c.getAPI().fieldEffect_PlayFieldSound("Sound/PL_Sound.img/Wz2_Abyss/shadow", 100);
            c.getAPI().getTopMsgFont("深渊之中弥漫着不寻常的气息，这是暗影即将出现的征兆！", 4, 30, 15, 0, 0)
        })
    } else {
        if (a % 30 == 0) {
            b.getPlayers().forEach(function (c) {
                c.getAPI().openNpc("深渊远征队_暗影现世")
            })
        } else {
            if (a % 30 == 3) {
                b.getPlayers().forEach(function (c) {
                    if (c.getMap(68913000).countMonsterById(9601295) > 0) {
                        c.getAPI().fieldEffect_ScreenMsg("Effect/EffectPL.img/AbyssShadow");
                        c.getAPI().fieldEffect_PlayFieldSound("Sound/PL_Sound.img/Wz2_Abyss/shadow", 100);
                        c.getAPI().getTopMsgFont("暗影即将消失在黑暗之中！必须在它消失之前消灭它！", 4, 30, 15, 0, 0)
                    }
                })
            } else {
                if (a % 30 == 3) {
                    b.getMapIds().forEach(function (c) {
                        var d = b.getMapInstance(c);
                        d.killMonster(9601295, true, true)
                    })
                }
            }
        }
    }
    b.schedule("暗影", 60 * 1000)
}

function 补给(a) {
    a.schedule("补给", 60 * 1000);
    if (a.rand(0, 20) != 10) {
        return
    }
    a.getMapIds().forEach(function (b) {
        var c = a.getMapInstance(b);
        if (c.getCharactersSize() == 0) {
            return
        }
        c.spawnMonsterOnGroundBelow(em.getMonster(a.rand(9601298, 9601299)), new java.awt.Point(a.rand(c.getLeft(), c.getRight()), a.rand(c.getTop(), c.getBottom() - 200)));
        c.getCharactersThreadsafe().forEach(function (d) {
            d.getAPI().playerMessage(-1, "发现了装满珍贵补给品的箱子！趁它还没被怪物群淹没，赶快回收吧。")
        })
    })
}

function onPlayerRegistered(c, b) {
    if (!(b.getAPI().getNowTimeString(3).equals(b.getAPI().getStringFromQuestInfo(64754, "reset")))) {
        b.getAPI().setStringForQuestInfo(64754, "reset", b.getAPI().getNowTimeString(3));
        var d = b.getAPI().getNumberFromQuestInfo(64753, "rank");
        b.getAPI().setNumberForQuestInfo(64754, "time", (d + 2) * 3600);
        b.getAPI().setNumberForQuestInfo(64754, "start", new Date().getTime())
    }
    b.setReviveCount(-100);
    var a = Math.min(1, b.getAPI().getNumberFromQuestInfo(64789, "map"));
    b.getAPI().warp(mapIds[a - 1], 3)
}

function onMonsterKilled(a, c, b) {
    if (c == 9601295) {
        var d = player.getMap().getMonsterByOid(b).getPosition();
        player.getAPI().spawnMobLimit(9601344, 1, d.x, d.y, 1);
        player.getAPI().playerMessage(-1, "消灭了暗影，找到了貌似是其他远征队留下的破旧背包作为战利品。")
    }
}

function onMapChanged(c, b, a) {
    var d = em.getNumberProperty("state");
    em.setProperty("stage" + d + "_kill", 0);
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
        default:
            return 0
    }
}

function onPlayerRevived(b, a) {
    return false
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    var f = b.getAPI().getNumberFromQuestInfo(64754, "start");
    var e = b.getAPI().getNumberFromQuestInfo(64754, "time");
    var d = new Date().getTime() - f;
    b.getAPI().setNumberForQuestInfo(64754, "time", Math.max(0, Math.floor(e - d / 1000)));
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onMonsterDamaged(b, a, d, e, c) {}

function onItemPickedUp() {};